// ignore_for_file: unused_local_variable

import 'package:flutter/material.dart';

class HomeModel {
  ///图片轮播
  final List<ImageBannersModel>? imageBanners;

  ///推荐分类
  final List<CategoryGridsModel>? categoryGrids;

  ///热门推荐
  final List<HotRecommendsModel>? hotRecommends;

  ///新鲜好物
  final List<FreshGoodsModel>? freshGoods;

  ///专题
  final List<ProjectsModel>? projects;

  ///推荐分类导航
  final List<CategoryBannersModel>? categoryBanners;

  //类名构造函数
  HomeModel(
      {this.categoryBanners,
      this.freshGoods,
      this.categoryGrids,
      this.hotRecommends,
      this.imageBanners,
      this.projects});

  //工厂构造函数
  factory HomeModel.fromJson(Map<String, dynamic> json) {
    // 将轮播图json数据进行转换
    List ImageBannersJson = json['imageBanners'];
    List<ImageBannersModel> ImageBanners = [];
    ImageBannersJson.forEach(
      (element) {
        ImageBanners.add(ImageBannersModel.fromJson(element));
      },
    );

    //将推荐分类json数据进行转换
    List CategoryGridsJson = json['categoryGrids'];
    List<CategoryGridsModel> categoryGrids = [];
    CategoryGridsJson.forEach(
      (element) {
        categoryGrids.add(CategoryGridsModel.fromJson(element));
      },
    );

    //热门推荐json数据进行转换
    List HotRecommendsJson = json['hotRecommends'];
    List<HotRecommendsModel> hotRecommends = [];
    HotRecommendsJson.forEach(
      (element) {
        hotRecommends.add(HotRecommendsModel.fromJson(element));
      },
    );

    //新鲜好物json数据转换
    List freshGoodsJson = json['freshGoods'];
    List<FreshGoodsModel> freshGoods = [];
    freshGoodsJson.forEach(
      (element) {
        freshGoods.add(FreshGoodsModel.fromJson(element));
      },
    );

    //专题推荐json数据转换
    List projectsJson = json['projects'];
    List<ProjectsModel> projects = [];
    projectsJson.forEach(
      (element) {
        projects.add(ProjectsModel.formJson(element));
      },
    );

    //商品推荐分类json数据转换
    List categoryBannersJson = json['categoryBanners'];
    List<CategoryBannersModel> categoryBanners = [];
    categoryBannersJson.forEach(
      (element) {
        categoryBanners.add(CategoryBannersModel.fromJson(element));
      },
    );

    return HomeModel(
      categoryBanners: categoryBanners,
      freshGoods: freshGoods,
      categoryGrids: categoryGrids,
      hotRecommends: hotRecommends,
      imageBanners: ImageBanners,
      projects: projects,
    );
  }
}

//图片轮播图模型数据
class ImageBannersModel {
  /// id
  final String? id;

  /// 图片地址
  final String? imgUrl;

  /// 跳转链接
  final String? hrefUrl;

  /// 类型
  final String? type;

  ImageBannersModel({this.id, this.imgUrl, this.hrefUrl, this.type});

  factory ImageBannersModel.fromJson(Map<String, dynamic> json) {
    return ImageBannersModel(
      id: json['id'],
      imgUrl: json['imgUrl'],
      hrefUrl: json['hrefUrl'],
      type: json['type'],
    );
  }
}

// 推荐分类数据模型
class CategoryGridsModel {
  ///分类id
  final String? id;

  ///分类名称
  final String? name;

  /// 分类商品
  final List<CategoryGoodsModel>? goods;

  ///图片
  final String? picture;
  CategoryGridsModel({this.id, this.name, this.goods, this.picture});

  factory CategoryGridsModel.fromJson(Map<String, dynamic> json) {
    // //将分类商品json数据进行转换
    // List goodsJSON = json['goods'];
    // List<CategoryGoodsModel> goods = [];
    // goodsJSON.forEach((element) {
    //   goods.add(CategoryGoodsModel.fromJson(element));
    // });

    return CategoryGridsModel(
      id: json['id'],
      name: json['name'],
      picture: json['picture'],
      goods: [],
    );
  }
}

//// 分类商品模型
class CategoryGoodsModel {
  /// 商品id
  final String? id;

  /// 商品名称
  final String? name;

  /// 商品描述
  final String? desc;

  /// 商品价格
  final String? price;

  /// 商品图标
  final String? picture;

  CategoryGoodsModel({this.id, this.name, this.desc, this.price, this.picture});

  factory CategoryGoodsModel.fromJson(Map<String, dynamic> json) {
    return CategoryGoodsModel(
      id: json['id'],
      name: json['name'],
      desc: json['desc'],
      price: json['price'],
      picture: json['picture'],
    );
  }
}

//热门推荐模型数据
class HotRecommendsModel {
  ///左侧图片
  final String? leftIcon;

  ///右侧图片
  final String? rightIcon;

  ///标题
  final String? title;

  ///简述
  final String? caption;

  HotRecommendsModel({
    this.leftIcon,
    this.rightIcon,
    this.title,
    this.caption,
  });

  factory HotRecommendsModel.fromJson(Map<String, dynamic> json) {
    return HotRecommendsModel(
      leftIcon: json['leftIcon'],
      rightIcon: json['rightIcon'],
      title: json['title'],
      caption: json['caption'],
    );
  }
}

//新鲜好物数据模型
class FreshGoodsModel {
  ///id
  final String? id;

  ///商品名称
  final String? name;

  ///商品描述
  final String? desc;

  ///商品名称
  final String? picture;

  FreshGoodsModel({this.id, this.name, this.desc, this.picture});

  factory FreshGoodsModel.fromJson(Map<String, dynamic> json) {
    return FreshGoodsModel(
      id: json['id'],
      name: json['name'],
      desc: json['desc'],
      picture: json['picture'],
    );
  }
}

//专题推荐数据模型
class ProjectsModel {
  ///创建者
  final String? creator;

  ///是否删除
  final num? isDelete;

  ///创建时间
  final String? createTime;

  ///更新时间
  final String? updateTime;

  ///专题id
  final String? id;

  ///专题分类id
  final String? classificationId;

  ///标题
  final String? title;

  ///副标题
  final String? summary;

  ///最低价格
  final num? lowestPrice;

  ///专题封面
  final String? cover;

  ///详情链接
  final String? detailsUrl;

  ///收藏数
  final num? collectNum;

  ///浏览数
  final num? viewNum;

  ///回复数
  final num? replyNum;

  ProjectsModel({
    this.creator,
    this.isDelete,
    this.createTime,
    this.updateTime,
    this.id,
    this.classificationId,
    this.title,
    this.summary,
    this.lowestPrice,
    this.cover,
    this.detailsUrl,
    this.collectNum,
    this.viewNum,
    this.replyNum,
  });

  factory ProjectsModel.formJson(Map<String, dynamic> json) {
    return ProjectsModel(
      creator: json['creator'],
      isDelete: json['isDelete'],
      createTime: json['createTime'],
      updateTime: json['updateTime'],
      id: json['id'],
      classificationId: json['classificationId'],
      summary: json['summary'],
      lowestPrice: json['lowestPrice'],
      cover: json['cover'],
      detailsUrl: json['detailsUrl'],
      collectNum: json['collectNum'],
      viewNum: json['viewNum'],
      replyNum: json['replyNum'],
    );
  }
}

//商品推荐分类列表
class CategoryBannersModel {
  ///前台类目Id
  final String? id;

  ///前台类目名称
  final String? name;

  ///	前台类目图片
  final String? picture;

  ///子类目集合
  final List? children;

  ///推荐商品集合
  final List? goods;

  CategoryBannersModel(
      {this.id, this.name, this.picture, this.children, this.goods});

  factory CategoryBannersModel.fromJson(Map<String, dynamic> json) {
    //子类目json数据转换
    List CategoryBannersChildrenJson = json['children'];
    List<CategoryBannersChildrenModel> children = [];
    CategoryBannersChildrenJson.forEach(
      (element) {
        children.add(CategoryBannersChildrenModel.fromJson(element));
      },
    );

    //推荐商品集合
    List CategoryBannersGoodsJson = json['goods'];
    List<CategoryBannersChildrenModel> goods = [];
    CategoryBannersGoodsJson.forEach(
      (element) {
        goods.add(CategoryBannersChildrenModel.fromJson(element));
      },
    );

    return CategoryBannersModel(
      id: json['id'],
      name: json['name'],
      picture: json['picture'],
      children: children,
      goods: goods,
    );
  }
}

//子类目集合
class CategoryBannersChildrenModel {
  ///	前台类目Id-子类目
  final String? id;

  ///	前台类目名称-子类目
  final String? name;

  ///前台类目图片-子类目
  final String? picture;

  CategoryBannersChildrenModel({this.id, this.name, this.picture});

  factory CategoryBannersChildrenModel.fromJson(Map<String, dynamic> json) {
    return CategoryBannersChildrenModel(
      id: json["id"],
      name: json["name"],
      picture: json["picture"],
    );
  }
}

//推荐商品集合
class CategoryBannersGoodsModel {
  /// 商品id
  final String? id;

  /// 商品名称
  final String? name;

  /// 商品描述
  final String? desc;

  /// 商品价格
  final String? price;

  /// 商品图片
  final String? picture;

  ///折扣
  final num? discount;

  ///销量
  final num? orderNum;

  CategoryBannersGoodsModel({
    this.id,
    this.name,
    this.desc,
    this.price,
    this.picture,
    this.discount,
    this.orderNum,
  });

  factory CategoryBannersGoodsModel.fromJson(Map<String, dynamic> json) {
    return CategoryBannersGoodsModel(
      id: json['id'],
      name: json['name'],
      desc: json['desc'],
      price: json['price'],
      picture: json['picture'],
      discount: json['discount'],
      orderNum: json['orderNum'],
    );
  }
}
